<?php echo $this->Html->script(array('print')); ?>
<div class="widget">
    
    <fieldset>
        <div id="areaImprimir">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tLight">
                <tr>
                    <td>
                        <h2>
                            <strong class="red">Nro.<?php echo $contador['Notaentrega']['numero']; ?></strong>
                        </h2>    
                    </td>
                    <td style="text-align: center">
                        <h2>
                            <strong class="green">
                                NOTA DE ENTREGA
                            </strong>
                        </h2>
                    </td>
                    <td style="text-align: right; padding-right: 20px">
                        <strong>La Paz, <?php echo $dia; ?>/<?php echo $mes ?>/<?php echo $anio; ?></strong>
                    </td>

                </tr>
                
                <tr>
                    <td><strong>Se&ntilde;or(es):</strong> 
                     
                    </td>
                    <td colspan="2"><h4><?php echo $cliente['Cliente']['nombre']; ?></h4></td>
                </tr>
                
            </table>

            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tLight">
                <?php echo $this->Form->create('Hojasproduccione'); ?>

                <!--datos cabecera-->
                <thead>
                    <tr>
                        <td style="width: 20%">Cantidad</td>
                        <td style="width: 20%">Formato</td>
                        <td style="width: 40%">Descripcion</td>
                        <td style="width: 10%">Precio</td>
                    </tr>
                </thead>
                <!--//fin datos cabecera-->

                <!--Form datos hoja de produccion-->          
                <tbody>
                    <?php $total = 0;
                    foreach ($hoja as $h): ?>
                        <tr>
                            <td><?php echo $h['Hojasproduccione']['cantidad']; ?></td>
                            <td>
                                <?php if ($h['Hojasproduccione']['tipo_id'] == 3): ?>
                                    <?php echo $h['Preciohoja']['nombre']; ?>
                                <?php else: ?>
                                    <?php echo $h['Hojasproduccione']['metrajeini']; ?>
                                    X
                                    <?php echo $h['Hojasproduccione']['metrajefin']; ?>
                                <?php endif; ?>
                            </td>

                            <td style="text-align:left;">
                                <?php echo $h['Hojasproduccione']['descripcion']; ?> -
                                <?php echo $h['Hojasproduccione']['tipo']; ?> -
                                <?php echo $h['Hojasproduccione']['cara']; ?>
                            </td>
                            <td style="text-align:right; padding-right: 20px">
                            <?php echo number_format($h['Hojasproduccione']['precio'], 2); ?> Bs.
                            </td>
                        </tr>
    <?php $total = $total + $h['Hojasproduccione']['precio'] ?>
<?php endforeach; ?>
                </tbody>  
                <tbody>
                    <tr>
                        <td colspan="3">TOTAL CANCELAR</td>
                        <td style="text-align:right; padding-right: 20px"><strong><?php echo number_format($total, 2); ?> Bs.</strong></td>      
                    </tr>


                    <?php if ($contador['Notaentrega']['tipo_pago'] == 'credito'): ?>
                    <tr>
                            <td>Tipo de Pago</td>
                            <td>al Cr&eacute;dito</td>
                            <td >
                                Saldo
                            </td>
                                <?php if ($contador['Notaentrega']['saldo'] != null || $contador['Notaentrega']['saldo'] != 0): ?>

                                <td style="text-align:right; padding-right: 20px">
                                    <?php echo number_format($contador['Notaentrega']['saldo'], 2); ?> Bs.
                                
                                </td>
                            <?php else: ?>
                                <td style="text-align:right; padding-right: 20px">
                                    <?php echo number_format($contador['Notaentrega']['totalpagado'], 2); ?> Bs.
                                </td>
                            
                        <?php endif; ?>
                        </tr>
                     <?php else: ?>
                        <tr>
                            <td>Tipo de Pago</td>
                            <td>al Contado</td>
                            <td style="text-align:right; padding-right: 20px">
                                Saldo
                            </td>
                            <td style="text-align:right; padding-right: 20px">
                                0 Bs.
                            </td>
                        </tr>
                    <?php endif; ?>
                    <tr>
                        <td style="border: 0px solid black;"></td>
                        <td style="border: 0px solid black; height: 63px;"><strong> Entregado Por</td>
                        <td style="border: 0px solid black;"></td>
                        <td style="border: 0px solid black;"></td>
                    </tr>
                </tbody>     
            </table>

        </div>   
    </fieldset>
</div>
<div>
    <tr>
        <td> 
         <a href="<?php echo $this->Html->url(array('action'=>'verhojaproduccion', $idtrabajo, $idhojaruta))?>" class="buttonS bGreen" id="btnImprimir">IMPRIMIR</a>
        </td>
        <td>
        <a href="<?php echo $this->Html->url(array('action' => 'editarnotaentrega', $id_entrega))
                    ?>" class="buttonM bRed">
                        <span class="icol-pricetag2"></span><span>EDITAR NOTA ENTREGA</span>
                    </a>
        <?php //echo $this->Html->link('EDITAR NOTA ENTREGA', array('action' => 'editarnotaentrega', $id_entrega)) ?>
        </td>
        <td>       
        <?php echo $this->Html->link("Atras", array('controller' => 'Trabajos', 'action' => 'index'), array('class' => 'buttonS bLightBlue', 'escape' => FALSE)); ?>
        </td>
    </tr>
</div>

<script type="text/javascript">

    $(document).ready(function() {

        $("#btnImprimir").click(function() {
            //console.log('click');
            //printElem({leaveOpen: true, printMode: 'popup'});
            printElem({ 
            printMode: 'popup',    
            overrideElementCSS: [
            '<?php echo $this->webroot; ?>css/imprimir.css',
                            {href: '<?php echo $this->webroot; ?>css/imprimir.css', media: 'print'}]
            //'http://www.imprenta.com/css/imprimir.css'] 
            });
        });

    });
    function printElem(options) {
        $('#areaImprimir').printElement(options);
    }
</script>